<template>
	<div class="list" ref="wrapper">
		<div>
			<div class="area border-topbottom">
				<div class="title">您的位置</div>
				<div class="button-list">
					<div class="button-wrapper">
						<div class="button">{{this.$store.state.city}}</div>
					</div>
				</div>
			</div>

			<div class="area border-topbottom">
				<div class="title" >热门城市</div>
				<div class="button-list">
					<div class="button-wrapper" v-for="item of hotCities" @click="handleCityClick(item.name)">
						<div class="button" >{{item.name}}</div>
					</div>
				</div>
			</div>

			<div class="area" 
				v-for="item,key of cities"
				:key="key"
				:ref="key"
				>
				<div class="title  border-topbottom" >{{key}}</div>
				<div class="item-list" v-for="val of item">
					<div class="item" @click="handleCityClick(val.name)">{{val.name}}</div>
				</div>
			</div>
			
		</div>
	</div>
</template>

<script>
import Bscroll from 'better-scroll'
export default {
		name:'CityList',
		mounted(){
			this.scroll = new Bscroll(this.$refs.wrapper);
		},
		methods:{
			handleCityClick(city){
				this.$store.commit('changeCity',city);
				this.$router.push('/');
			}
		},
		props:{
			cities:Object,
			hotCities:Array,
			letter:String
		},
		watch:{
			letter(){
				if(this.letter){
					const element = this.$refs[this.letter][0]
					this.scroll.scrollToElement(element);
				}
			}
		}
	}
</script>

<style scoped>
	.border-topbottom:before{
		background:#EDEDED;
	}
	.border-topbottom:after{
		background: #EDEDED;
	}
	.list{
		position: absolute;
		top: 1.60rem;
		left: 0;
		bottom: 0;
		right: 0;
		overflow: hidden;
	}
	.title{
		height: .6rem;
		line-height: .6rem;
		padding-left:.2rem;
		background: #EDEDED;
		font-size: .26rem;
	}
	.button-list{
		padding: 0.1rem .6rem .1rem .1rem;
		overflow: hidden;
	}
	.button-wrapper{
		float: left;
		width: 32%;
		margin-top:.15rem ;
		margin-right: .1rem;
	}
	.button-list .button-wrapper:nth-child(3n){
		margin-right: 0rem;
	}
	.button{
		text-align: center;
		border-radius: .1rem;
		padding: .1rem;
		box-sizing: border-box;
		border:.02rem solid #ccc;
	}
	.item-list .item{
		height: .66rem;
		line-height: .66rem;
		padding-left: .2rem;
		border-bottom: .01rem solid  #EDEDED;

		
	}
</style>